package shuati.chuanzhibei;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * @Date : 2022/11/26
 * @Description:
 */
public class PB {
    static final Long N=1000010L;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> A = new ArrayList<>(),B=new ArrayList<>();
        int a,b;
        a=sc.nextInt();
        b=sc.nextInt();
        //倒序存储，方便直接计算进位 将每一位字符转换为数字进行存储
        for (int i = a-1; i >=0; i--) {
            A.add(sc.nextInt());
        }//A-[6,5,4,3,2,1]
        Collections.reverse(A);

        for (int i = b-1; i >=0; i--) {
            B.add(sc.nextInt());
        }
        Collections.reverse(B);

        List<Integer> C=add(A,B);

        //注意同样需要倒序输出
        for (int i = C.size()-1; i >=0; i--) {
            System.out.printf(i==0?"%d":"%d ",C.get(i));

        }
    }
    public static List<Integer> add(List<Integer> A, List<Integer> B){
        List<Integer> C =new ArrayList<>();
        int t=0;
        for (int i = 0; i < A.size()||i<B.size(); i++) {
            if(i<A.size()) t+= A.get(i);
            if(i<B.size()) t+= B.get(i);
            C.add(t%(i+2));
            t/=(i+2);
        }
        if(t!=0) C.add(1);
        return C;
    }
}
